<template>
    <div class="apiSearchContainer">
        <span class="inputLabel">微服务名称</span>
        <el-input v-model="serviceInstanceApplicationSearchData.applicationName" placeholder="微服务名称" class="searchInfoInput"></el-input>

        <el-button type="primary" icon="SearchOutlined" :loading="searchLoading" class="searchButtonClass" @click="queryApiInfo()">搜索</el-button>
        <el-button icon="RedoOutlined" @click="resetInput()">重置</el-button>
    </div>
</template>

<script name="ServiceInstanceSearch" setup lang="ts">
import {applicationNacosInfoQuery} from "@/request/service";
import {computed, ref} from "vue";
import {useServiceInstanceStore} from "@/stores/serviceManage/serviceInstance";

let searchLoading = ref(false);

let serviceInstanceApplicationSearchData = computed(() => {return useServiceInstanceStore().serviceInstanceApplicationSearchData});

function queryApiInfo() {
    searchLoading.value = true
    applicationNacosInfoQuery(serviceInstanceApplicationSearchData.value).then(res => {
        if (res["code"] === '200') {
            useServiceInstanceStore().resetServiceInstanceApplicationDataList(res.data);
        }
        searchLoading.value = false
    }).catch(res => {
        searchLoading.value = false
    })
}

function resetInput() {
    useServiceInstanceStore().resetServiceInstanceApplicationSearchData({
        applicationName: ""
    })
}
</script>

<style scoped lang="less">
.apiSearchContainer {
    width: 100%;
    height: 10%;
    .searchInfoInput {
        width: 15%;
        padding-left: 1%;
    }
    .inputLabel {
        padding-left: 1%;
        font-weight: 700;
        font-size: 15px;
        color: #606266;
    }
    .searchButtonClass {
        margin-left: 1%;
    }
}
</style>